#include "StdAfx.h"
#include "FryEntity.h"
#include "MobileGame.h"

FryEntity_cl::FryEntity_cl(void)
{
}

FryEntity_cl::~FryEntity_cl(void)
{
}

void FryEntity_cl::InitFunction()
{
	m_pRigidBody = NULL;
	m_bTocuhFrypan = false;
	m_iFryVisibleBitMask = GetVisibleBitmask();
}

void FryEntity_cl::ThinkFunction()
{
}

void FryEntity_cl::MessageFunction(int iID, INT_PTR iParamA, INT_PTR iParamB)
{
// 	switch(iID)
// 	{
// 	case VIS_MSG_HAVOK_ONCOLLISION :
// 		{
// 			vHavokCollisionInfo_t * pInfo = (vHavokCollisionInfo_t*) iParamA;
// 
// 			_int64 test = CMobileGame::GetInstance().GetFrypanUniqueID();
// 			if( (pInfo->m_pSenderTarget[0] != NULL && pInfo->m_pSenderTarget[0]->GetUniqueID() == test)
// 				|| ( pInfo->m_pSenderTarget[1] != NULL && pInfo->m_pSenderTarget[1]->GetUniqueID() == test) )
// 			{
// 				m_bTocuhFrypan = true;
// 				m_pRigidBody->SetFriction(0.3f);
// 			}
// 			else
// 			{
// 	//			m_pRigidBody->SetFriction(1.f);
// 			}
// 			
// 			break;
// 		}
// 	}
	VisBaseEntity_cl::MessageFunction( iID, iParamA, iParamB );
}

void FryEntity_cl::RemoveRB()
{
//	m_pRigidBody->Remove
	m_pRigidBody = NULL;
}

void FryEntity_cl::CreateRigidBody()
{
	m_pRigidBody = new vHavokRigidBody();
	m_pRigidBody->Initialize();
	vHavokRigidBody::InitTemplate initTempl;
	float fScale = 1.f;
	hkvVec3 vScale(fScale,fScale,fScale);
	m_pRigidBody->InitBoxRb(GetMesh(),vScale,initTempl);
	m_pRigidBody->SetFriction(0.3f);
	m_pRigidBody->SetRestitution(0.0f);
//	m_pRigidBody->SetDebugRendering(TRUE);
	m_pRigidBody->SetMass(10.f);
	AddComponent(m_pRigidBody);
}

void FryEntity_cl::RigidbodyReset()
{
	m_pRigidBody->Initialize();
	vHavokRigidBody::InitTemplate initTempl;
	float fScale = 1.f;
	hkvVec3 vScale(fScale,fScale,fScale);
	m_pRigidBody->InitBoxRb(GetMesh(),vScale,initTempl);
 	m_pRigidBody->SetFriction(0.3f);
 	m_pRigidBody->SetRestitution(0.0f);
//	m_pRigidBody->SetDebugRendering(TRUE);
	m_pRigidBody->SetMass(10.f);
}

void FryEntity_cl::SetVisible(bool visible)
{
	VisBaseEntity_cl::SetVisibleBitmask(visible ? m_iFryVisibleBitMask:0);

	if(m_pRigidBody)
	{
		m_pRigidBody->SetActive(visible);
	//	if(!visible)
		//	RigidbodyReset();
	}
}

void FryEntity_cl::SetPosition( const hkvVec3& vPos )
{
	if(m_pRigidBody)
		m_pRigidBody->SetPosition(vPos);

	VisBaseEntity_cl::SetPosition(vPos);
}

V_IMPLEMENT_SERIAL(FryEntity_cl, VisBaseEntity_cl, 0, Vision::GetEngineModule());
START_VAR_TABLE(FryEntity_cl, VisBaseEntity_cl, "FryEntity", 0, NULL)
END_VAR_TABLE
